﻿// CardEncoderDemo.cpp : 定义应用程序的入口点。
//

#include "stdafx.h"
#include "CardEncoderDemo.h"
#include "HttpRequest.h"
#include "tool.h"
#include "hotel.h"
#include "json/json.h"
#include <time.h>

#define MAX_LOADSTRING 100
#define HOTELINFO_MAXLEN 20000

// 全局变量:
HINSTANCE hInst;                                // 当前实例
WCHAR szTitle[MAX_LOADSTRING];                  // 标题栏文本
WCHAR szWindowClass[MAX_LOADSTRING];            // 主窗口类名
HWND output;
CHAR hotelInfoStr[HOTELINFO_MAXLEN];

// 调用方法
void configServer(HWND hWnd);		// 配置服务器地址及获取hotelInfo
void connectComm(HWND hWnd);		// 连接设备串口
void initCardEncoder(HWND hWnd);	// 配置发卡器
void initCard(HWND hWnd);			// 写酒店专用卡
void stopInitCard(HWND hWnd);		// 停止发卡操作
void writeCard(HWND hWnd);			// 添加单条IC卡数据
void cancelCard(HWND hWnd);			// 挂失IC卡
void readCard(HWND hWnd);			// 读取IC卡内数据
void clearCard(HWND hWnd);			// 清空IC卡内数据
void getCardNo(HWND hWnd);			// 获取IC卡卡号
void deInitCard(HWND hWnd);			// 恢复空白卡
void getVersion(HWND hWnd);			// 获取设备版本信息
void initConstructionCard(HWND hWnd);		// 发工程卡
void beep(HWND hWnd);				// 蜂鸣器发声
void disconnectComm(HWND hWnd);		// 断开设备连接
void setSectors(HWND hWnd);			// 设置使用的扇区
void getSectors(HWND hWnd);			// 读取扇区设置

// 此代码模块中包含的函数的前向声明:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: 在此处放置代码。

    // 初始化全局字符串
    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadStringW(hInstance, IDC_CARDENCODERDEMO, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    // 执行应用程序初始化:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CARDENCODERDEMO));

    MSG msg;

    // 主消息循环:
    while (GetMessage(&msg, nullptr, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}



//
//  函数: MyRegisterClass()
//
//  目标: 注册窗口类。
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEXW wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CARDENCODERDEMO));
    wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_CARDENCODERDEMO);
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassExW(&wcex);
}

//
//   函数: InitInstance(HINSTANCE, int)
//
//   目标: 保存实例句柄并创建主窗口
//
//   注释:
//
//        在此函数中，我们在全局变量中保存实例句柄并
//        创建和显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // 将实例句柄存储在全局变量中

   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

void setErrorMsg(LPCSTR methodName, int errorCode, LPCSTR message) {
	char resStr[50];
	string res;
	sprintf_s(resStr, "%s	return:%d\r\n", methodName, errorCode);
	res.append(resStr);
	if (errorCode == 0) res.append(message);
	res.append("\r\n");
	SendMessageA(output, EM_SETSEL, -1, -1);
	SendMessageA(output, EM_REPLACESEL, true, LPARAM(res.c_str()));
	SendMessageA(output, WM_VSCROLL, SB_BOTTOM, 0);
}

//
//  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目标: 处理主窗口的消息。
//
//  WM_COMMAND  - 处理应用程序菜单
//  WM_PAINT    - 绘制主窗口
//  WM_DESTROY  - 发送退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
	case WM_CREATE: 
	{
		CreateWindow(TEXT("button"), TEXT("设置服务器地址并获取hotelInfo"), WS_CHILD | WS_VISIBLE, 10, 10, 150, 25, hWnd, (HMENU)CEIDB_CONFIG_SERVER, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("连接设备串口"), WS_CHILD | WS_VISIBLE, 10, 40, 150, 25, hWnd, (HMENU)CEIDB_CONNECT_COMM, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("配置发卡器"), WS_CHILD | WS_VISIBLE, 10, 70, 150, 25, hWnd, (HMENU)CEIDB_INIT_CARD_ENCODER, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("写酒店专用卡"), WS_CHILD | WS_VISIBLE, 10, 100, 150, 25, hWnd, (HMENU)CEIDB_INIT_CARD, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("停止发卡操作"), WS_CHILD | WS_VISIBLE, 10, 130, 150, 25, hWnd, (HMENU)CEIDB_STOP_INIT_CARD, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("添加单条IC卡数据"), WS_CHILD | WS_VISIBLE, 10, 160, 150, 25, hWnd, (HMENU)CEIDB_WRITE_CARD, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("读取IC卡内数据"), WS_CHILD | WS_VISIBLE, 10, 190, 150, 25, hWnd, (HMENU)CEIDB_READ_CARD, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("清空IC卡内数据"), WS_CHILD | WS_VISIBLE, 10, 220, 150, 25, hWnd, (HMENU)CEIDB_CLEAR_CARD, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("获取IC卡卡号"), WS_CHILD | WS_VISIBLE, 10, 250, 150, 25, hWnd, (HMENU)CEIDB_GET_CARD_NO, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("恢复空白卡"), WS_CHILD | WS_VISIBLE, 10, 280, 150, 25, hWnd, (HMENU)CEIDB_DE_INIT_CARD, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("获取设备版本信息"), WS_CHILD | WS_VISIBLE, 10, 310, 150, 25, hWnd, (HMENU)CEIDB_GET_VERSION, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("发工程卡"), WS_CHILD | WS_VISIBLE, 10, 340, 150, 25, hWnd, (HMENU)CEIDB_INIT_CONSTRUCTION_CARD, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("蜂鸣器发声"), WS_CHILD | WS_VISIBLE, 10, 370, 150, 25, hWnd, (HMENU)CEIDB_BEEP, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("断开设备连接"), WS_CHILD | WS_VISIBLE, 10, 400, 150, 25, hWnd, (HMENU)CEIDB_DISCONNECT_COMM, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("挂失IC卡"), WS_CHILD | WS_VISIBLE, 400, 280, 150, 25, hWnd, (HMENU)CEIDB_CANCEL_CARD, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

		CreateWindow(TEXT("static"), TEXT("clientId: "), WS_CHILD | WS_VISIBLE | SS_RIGHT, 170, 10, 100, 25, hWnd, (HMENU)IDC_STATIC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("edit"), TEXT(CLIENT_ID_COMMON), WS_CHILD | WS_VISIBLE | WS_BORDER | WS_OVERLAPPED, 275, 10, 300, 25, hWnd, (HMENU)CEIDC_CLIENT_ID, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("static"), TEXT("clientSecret: "), WS_CHILD | WS_VISIBLE | SS_RIGHT, 170, 40, 100, 25, hWnd, (HMENU)IDC_STATIC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("edit"), TEXT(CLIENT_SECRET_COMMON), WS_CHILD | WS_VISIBLE | WS_BORDER | WS_OVERLAPPED, 275, 40, 300, 25, hWnd, (HMENU)CEIDC_CLIENT_SECRET, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

		CreateWindow(TEXT("static"), TEXT("服务器地址："), WS_CHILD | WS_VISIBLE | SS_RIGHT, 170, 70, 100, 25, hWnd, (HMENU)IDC_STATIC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("edit"), TEXT("https://api.ttlock.com/"), WS_CHILD | WS_VISIBLE | WS_BORDER | WS_OVERLAPPED, 275, 70, 300, 25, hWnd, (HMENU)CEIDC_SERVER, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		
		CreateWindow(TEXT("static"), TEXT("HOTEL INFO："), WS_CHILD | WS_VISIBLE | SS_RIGHT, 170, 100, 100, 25, hWnd, (HMENU)IDC_STATIC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("static"), TEXT(""), WS_CHILD | WS_VISIBLE | SS_LEFT | BS_MULTILINE, 275, 100, 600, 90, hWnd, (HMENU)CEIDS_HOTELINFO, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		
		CreateWindow(TEXT("static"), TEXT("串口名称："), WS_CHILD | WS_VISIBLE | SS_RIGHT, 170, 220, 100, 25, hWnd, (HMENU)IDC_STATIC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("edit"), TEXT("COM4"), WS_CHILD | WS_VISIBLE | WS_BORDER, 275, 220, 80, 25, hWnd, (HMENU)CEIDC_COMM, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

		CreateWindow(TEXT("static"), TEXT("楼栋号："), WS_CHILD | WS_VISIBLE | SS_RIGHT, 170, 250, 100, 25, hWnd, (HMENU)IDC_STATIC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("edit"), TEXT("15"), WS_CHILD | WS_VISIBLE | WS_BORDER, 275, 250, 50, 25, hWnd, (HMENU)CEIDC_BUILDNO, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("static"), TEXT("楼层号："), WS_CHILD | WS_VISIBLE | SS_RIGHT, 170, 280, 100, 25, hWnd, (HMENU)IDC_STATIC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("edit"), TEXT("18"), WS_CHILD | WS_VISIBLE | WS_BORDER, 275, 280, 50, 25, hWnd, (HMENU)CEIDC_FLOORNO, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("static"), TEXT("锁MAC地址："), WS_CHILD | WS_VISIBLE | SS_RIGHT, 170, 310, 100, 25, hWnd, (HMENU)IDC_STATIC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("edit"), TEXT("000000000000"), WS_CHILD | WS_VISIBLE | WS_BORDER | ES_WANTRETURN | ES_MULTILINE, 275, 310, 120, 25, hWnd, (HMENU)CEIDC_MAC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		
		CreateWindow(TEXT("static"), TEXT("挂失IC卡号："), WS_CHILD | WS_VISIBLE | SS_RIGHT, 400, 220, 100, 25, hWnd, (HMENU)IDC_STATIC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("edit"), TEXT("1084561231"), WS_CHILD | WS_VISIBLE | WS_BORDER, 520, 220, 90, 25, hWnd, (HMENU)CEIDC_CANCEL_CARDNO, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("static"), TEXT("挂失时间戳："), WS_CHILD | WS_VISIBLE | SS_RIGHT, 400, 250, 100, 25, hWnd, (HMENU)IDC_STATIC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("edit"), TEXT("1561106805"), WS_CHILD | WS_VISIBLE | WS_BORDER, 520, 250, 90, 25, hWnd, (HMENU)CEIDC_CANCEL_TIMESTAMP, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

		CreateWindow(TEXT("static"), TEXT("使用扇区："), WS_CHILD | WS_VISIBLE | SS_RIGHT, 170, 340, 100, 25, hWnd, (HMENU)IDC_STATIC, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("edit"), TEXT("0000000000000000"), WS_CHILD | WS_VISIBLE | WS_BORDER, 275, 340, 150, 25, hWnd, (HMENU)CEIDC_SECTORS, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("设置使用的扇区"), WS_CHILD | WS_VISIBLE, 170, 370, 150, 25, hWnd, (HMENU)CEIDB_SET_SECTORS, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CreateWindow(TEXT("button"), TEXT("读取扇区设置"), WS_CHILD | WS_VISIBLE, 170, 400, 150, 25, hWnd, (HMENU)CEIDB_GET_SECTORS, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

		output = CreateWindow(TEXT("edit"), NULL,
			WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
			WS_BORDER | ES_LEFT | ES_MULTILINE |
			ES_NOHIDESEL | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
			10, 420, 420, 200, hWnd, (HMENU)CEIDE_OUTPUT, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
		CE_SetLog(true, "./encoder_log");
		
	}
	case WM_SIZE: 
	{
		MoveWindow(output, 10, 450, 500, 200, TRUE);
	}
		break;
    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            // 分析菜单选择:
            switch (wmId)
            {
			case CEIDB_CONFIG_SERVER:
				configServer(hWnd);
				break;
			case CEIDB_CONNECT_COMM:
				connectComm(hWnd);
				break;
			case CEIDB_INIT_CARD_ENCODER:
				initCardEncoder(hWnd);
				break;
			case CEIDB_INIT_CARD:
				initCard(hWnd);
				break;
			case CEIDB_STOP_INIT_CARD:
				stopInitCard(hWnd);
				break;
			case CEIDB_WRITE_CARD:
				writeCard(hWnd);
				break;
			case CEIDB_READ_CARD:
				readCard(hWnd);
				break;
			case CEIDB_CANCEL_CARD:
				cancelCard(hWnd);
				break;
			case CEIDB_CLEAR_CARD:
				clearCard(hWnd);
				break;
			case CEIDB_GET_CARD_NO:
				getCardNo(hWnd);
				break;
			case CEIDB_DE_INIT_CARD:
				deInitCard(hWnd);
				break;
			case CEIDB_GET_VERSION:
				getVersion(hWnd);
				break;
			case CEIDB_INIT_CONSTRUCTION_CARD:
				initConstructionCard(hWnd);
				break;
			case CEIDB_BEEP:
				beep(hWnd);
				break;
			case CEIDB_GET_SECTORS:
				getSectors(hWnd);
				break;
			case CEIDB_SET_SECTORS:
				setSectors(hWnd);
				break;
			case CEIDB_DISCONNECT_COMM:
				disconnectComm(hWnd);
				break;
            case IDM_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                break;
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
            // TODO: 在此处添加使用 hdc 的任何绘图代码...
            EndPaint(hWnd, &ps);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

// “关于”框的消息处理程序。
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        break;
    }
    return (INT_PTR)FALSE;
}

char *getEditStr(HWND hWnd, int comm) {
	WCHAR server_w[300];
	GetWindowText(GetDlgItem(hWnd, comm), server_w, 300);
	return wchar2char(server_w);
}

void configServer(HWND hWnd) {
	WCHAR server_w[128];
	char *server = NULL;
	GetWindowText(GetDlgItem(hWnd, CEIDC_SERVER), server_w, 128);
	server = wchar2char(server_w);
	int configRes = CE_ConfigServer(server);
	setErrorMsg("CE_ConfigServer", configRes, "");

	time_t tt = time(NULL);
	struct tm ptr;
	localtime_s(&ptr, &tt);
	HttpRequest *httpRequest = new HttpRequest();
	string result;
	char url[150];
	char *clientId = getEditStr(hWnd, CEIDC_CLIENT_ID);
	char *clientSecret = getEditStr(hWnd, CEIDC_CLIENT_SECRET);
	sprintf_s(url, "%s/v3/hotel/getInfo?clientId=%s&clientSecret=%s&date=%ld000", server, clientId, clientSecret, (long)tt);
	if (httpRequest->getData(url, &result) != 0) {
		setErrorMsg("Get HotelInfo", 1, "请求失败");
		return ;	//请求失败
	}
	setErrorMsg("Get HotelInfo", 0, result.c_str());
	Json::Reader reader;
	Json::Value root; 
	if (!reader.parse(result.c_str(), root)) {
		setErrorMsg("Get HotelInfo", 2, "请求解析失败");
		return ;				//解析JSON失败
	}
	setErrorMsg("Get HotelInfo", 0, "");
	memset(hotelInfoStr, 0, HOTELINFO_MAXLEN);
	strcpy_s(hotelInfoStr, root["hotelInfo"].asString().c_str());
	SetWindowText(GetDlgItem(hWnd, CEIDS_HOTELINFO), char2wchar(root["hotelInfo"].asString().c_str()));
}

void connectComm(HWND hWnd) {
	char *comm = getEditStr(hWnd, CEIDC_COMM);
	int connRes = CE_ConnectComm(comm);
	setErrorMsg("CE_ConnectComm", connRes, "");
}

void initCardEncoder(HWND hWnd) {
	char *hotelInfo = getEditStr(hWnd, CEIDS_HOTELINFO);
	int res = CE_InitCardEncoder(hotelInfoStr);
	setErrorMsg("CE_InitCardEncoder", res, "");
}

void initCard(HWND hWnd) {
	char *hotelInfo = getEditStr(hWnd, CEIDS_HOTELINFO);
	int res = CE_InitCard(hotelInfoStr);
	setErrorMsg("CE_InitCard", res, "");
}

void stopInitCard(HWND hWnd) {
	int res = CE_StopInitCard();
	setErrorMsg("CE_StopInitCard", res, "");
}

void writeCard(HWND hWnd) {
	char *hotelInfo = getEditStr(hWnd, CEIDS_HOTELINFO);
	time_t tt = time(NULL);
	struct tm ptr;
	localtime_s(&ptr, &tt);
	int buildNo = atoi(getEditStr(hWnd, CEIDC_BUILDNO));
	int floorNo = atoi(getEditStr(hWnd, CEIDC_FLOORNO));
	char *mac = getEditStr(hWnd, CEIDC_MAC);
	int res = CE_WriteCard(hotelInfoStr, buildNo, floorNo, mac, (long)(tt + 24 * 60 * 60), true);
	setErrorMsg("CE_WriteCard", res, "");
}

void cancelCard(HWND hWnd) {
	char *hotelInfo = getEditStr(hWnd, CEIDS_HOTELINFO);
	char *cardNo = getEditStr(hWnd, CEIDC_CANCEL_CARDNO);
	long timestamp = atol(getEditStr(hWnd, CEIDC_CANCEL_TIMESTAMP));
	int res = CE_CancelCard(hotelInfoStr, cardNo, timestamp);
	setErrorMsg("CE_CancelCard", res, "");
}

void readCard(HWND hWnd) {
	char *hotelInfo = getEditStr(hWnd, CEIDS_HOTELINFO);
	char *hotelArray = NULL;
	int res = CE_ReadCard(hotelInfoStr, &hotelArray);
	setErrorMsg("CE_ReadCard", res, hotelArray);
}

void clearCard(HWND hWnd) {
	char *hotelInfo = getEditStr(hWnd, CEIDS_HOTELINFO);
	int res = CE_ClearCard(hotelInfoStr);
	setErrorMsg("CE_ClearCard", res, "");
}


void getCardNo(HWND hWnd) {
	char *cardNo = NULL;
	int res = CE_GetCardNo(&cardNo);
	setErrorMsg("CE_GetCardNo", res, cardNo);
}


void deInitCard(HWND hWnd) {
	char *hotelInfo = getEditStr(hWnd, CEIDS_HOTELINFO);
	int res = CE_DeInitCard(hotelInfoStr);
	setErrorMsg("CE_DeInitCard", res, "");
}

void getVersion(HWND hWnd) {
	char *version = NULL;
	int res = CE_GetVersion(&version);
	setErrorMsg("CE_GetVersion", res, version);
}

void initConstructionCard(HWND hWnd) {
	int res = CE_InitConstructionCard();
	setErrorMsg("CE_InitConstructionCard", res, "");
}

void beep(HWND hWnd) {
	int res = CE_Beep(100, 100, 4);
	setErrorMsg("CE_Beep", res, "");
}

void disconnectComm(HWND hWnd) {
	int res = CE_DisconnectComm();
	setErrorMsg("CE_DisconnectComm", res, "");
}

void setSectors(HWND hWnd) {
	char *sectors = getEditStr(hWnd, CEIDC_SECTORS);
	int res = CE_SetSectors(sectors);
	setErrorMsg("CE_SetSectors", res, "");
}

void getSectors(HWND hWnd) {
	char *sectors = NULL;
	int res = CE_GetSectors(&sectors);
	setErrorMsg("CE_GetSectors", res, sectors);
}